{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="body"}
<form class="layui-form p-page">
	<h3 class="pb-2">人事调动</h3>
	{if condition="$id eq 0"}
	<table class="layui-table layui-table-form">
		<tr>
			<td class="layui-td-gray-2">调动员工<font>*</font></td>
			<td>				
				<input type="text" name="name" placeholder="请选择需要调动的员工" lay-reqText="请选择需要调动的员工" lay-verify="required" autocomplete="off" class="layui-input" readonly>
				<input type="hidden" name="uid" value="0">
				<input type="hidden" name="from_did" value="0">
			</td>
			<td class="layui-td-gray">调出部门<font>*</font></td>
			<td>
				<input type="text" name="from_department" lay-verify="required" autocomplete="off" placeholder="请选择调出部门" lay-reqText="请选择调出部门" class="layui-input" readonly>
			</td>
		</tr>
		<tr>
			<td class="layui-td-gray">调动日期<font>*</font></td>
			<td><input type="text" name="move_time" lay-verify="required" autocomplete="off" placeholder="请选择调动日期" lay-reqText="请选择调动日期" readonly class="layui-input tool-time"></td>
			<td class="layui-td-gray">调入部门<font>*</font></td>
			<td>
				<input type="text" name="to_department" lay-verify="required" autocomplete="off" placeholder="请选择调入部门" lay-reqText="请选择调入部门" class="layui-input picker-oa" data-types="department" readonly>
				<input type="hidden" name="to_did" value="0">
			</td>
		</tr>
		<tr>
			<td class="layui-td-gray">调动原因<font>*</font></td>
			<td colspan="3">				
				<textarea name="remark" placeholder="请输入调动原因" class="layui-textarea" lay-verify="required" lay-reqText="请输入调动原因"></textarea>
			</td>
		</tr>
		<tr>
			<td class="layui-td-gray">附件 <button type="button" class="layui-btn layui-btn-xs" id="uploadBtn"><i class="layui-icon"></i></button></td>
			<td colspan="3">
				<div class="layui-row" id="uploadBox">
					<input data-type="file" type="hidden" name="file_ids" value="">
				</div>
			</td>
		</tr>
	</table>
	{else/}
	<table class="layui-table layui-table-form">
		<tr>
			<td class="layui-td-gray-2">调动员工</td>
			<td>{$detail.name}</td>
			<td class="layui-td-gray">调出部门</td>
			<td>{$detail.from_department}</td>
		</tr>
		<tr>
			<td class="layui-td-gray">调动日期<font>*</font></td>
			<td><input type="text" name="move_time" value="{$detail.move_time|default=''}" lay-verify="required" autocomplete="off" placeholder="请选择调动日期" lay-reqText="请选择调动日期" readonly class="layui-input tool-time"></td>
			<td class="layui-td-gray">调入部门<font>*</font></td>
			<td>
				<input type="text" name="to_department" lay-verify="required" autocomplete="off" placeholder="请选择调入部门" lay-reqText="请选择调入部门" class="layui-input picker-oa" data-types="department" readonly value="{$detail.to_department}">
				<input type="hidden" name="to_did" value="0" value="{$detail.to_did}">
			</td>
		</tr>
		<tr>
			<td class="layui-td-gray">调动原因<font>*</font></td>
			<td colspan="3">				
				<textarea name="remark" placeholder="请输入调动原因" class="layui-textarea" lay-verify="required" lay-reqText="请输入调动原因">{$detail.remark|default=''}</textarea>
			</td>
		</tr>
		<tr>
			<td class="layui-td-gray">附件 <button type="button" class="layui-btn layui-btn-xs" id="uploadBtn"><i class="layui-icon"></i></button></td>
			<td colspan="3">
				<div class="layui-row" id="uploadBox">
					<input data-type="file" type="hidden" name="file_ids" value="{$detail.file_ids|default=''}">
					{notempty name="$detail.file_ids"}
					{volist name="$detail.file_array" id="vo"}
					<div class="layui-col-md4">{:file_card($vo)}</div>
					{/volist}
					{/notempty}
				</div>
			</td>
		</tr>
	</table>
	{/if}
	<div id="checkBox" data-status="{$detail.check_status|default=0}" data-id="{$detail.id|default=0}" data-checkflowid="{$detail.check_flow_id|default=0}" class="pt-3"></div>
	<div class="pt-4">
		<input type="hidden" name="id" value="{$id}" />
		<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
		<button type="reset" class="layui-btn layui-btn-primary">重置</button>
	</div>
</form>
{/block}
<!-- /主体 -->
<!-- 脚本 -->
{block name="script"}
<script>
	const moduleInit = ['tool','oaPicker','oaCheck','uploadPlus'];
	function gouguInit() {
		var form = layui.form,tool=layui.tool,oaCheck=layui.oaCheck,oaPicker=layui.oaPicker,uploadPlus=layui.uploadPlus;
		oaCheck.init({
			check_name:'department_change',
			check_btn:0
		});	
		var fileUp = new uploadPlus();
		
		$('body').on('click','[name="from_department"]',function(){
			var val=$(this).val();
			if(val==''){
				layer.msg('请先选择需要调动的员工');
			}			
		});		
		
		//选择员工弹窗	
		$('body').on('click','[name="name"]',function () {
			let that = $(this);
			let ids=that.next().val()+'',names = that.val()+'';
			oaPicker.employeeInit({
				ids:ids,
				names:names,
				type:1,//1是单选，2是多选
				callback:function(data){
					//这里是选择后的回调方法，可以根据具体需求自定义写哦
					let select_id=[],select_name=[],select_did=[],select_department=[];
					for(var a=0; a<data.length;a++){
						select_id.push(data[a].id);
						select_name.push(data[a].name);
						select_did.push(data[a].did);
						select_department.push(data[a].department);
					}
					that.val(select_name.join(','));
					that.next().val(select_id.join(','));
					$('[name="uid"]').val(select_id.join(','));
					$('[name="name"]').val(select_name.join(','));
					$('[name="from_did"]').val(select_did.join(','));
					$('[name="from_department"]').val(select_department.join(','));
				}
			});
		}); 


		//监听提交
		form.on('submit(webform)', function (data) {
			if(data.field.uid==0 || data.field.from_did==0){
				layer.msg('请选择要调用的员工');
				return false;
			}
			if(data.field.to_did==''){
				layer.msg('请选择要调入的部门');
				return false;
			}			
			if(data.field.to_did==data.field.from_did){
				layer.msg('要调入的部门和调出的部门不能是同一个部门');
				return false;
			}
			let callback = function (e) {
				layer.msg(e.msg);
				if (e.code == 0) {
					let checkCallback = function (e) {
						layer.msg(e.msg);
						if (e.code == 0) {
							tool.sideClose(1000);				
						}
					}
					data.field.check_name = 'department_change';
					data.field.action_id = e.data.return_id;
					oaCheck.submit(data.field,checkCallback);
				}
			}
			let clickbtn = $(this);
			tool.post("/user/personal/change_add", data.field, callback,clickbtn);
			return false;
		});
	}

</script>
{/block}
<!-- /脚本 -->